package com.etcsoft.pagedesigner.wizard;

import org.eclipse.core.resources.IFolder;
import org.eclipse.jface.wizard.Wizard;

import com.etcsoft.pagedesigner.common.Messages;
import com.etcsoft.pagedesigner.model.ProjectItem;
import com.etcsoft.pagedesigner.model.ProjectManager;
import com.etcsoft.pagedesigner.util.CommonUtil;

public class NewFolderWizard extends Wizard {
    private NewFolderWizardFirstPage firstPage;

    public NewFolderWizard() {
        this.setWindowTitle(Messages.DESC_FOLDER_WIZARD_TITLE);
    }

    @Override
    public void addPages() {
        this.firstPage = new NewFolderWizardFirstPage();

        this.addPage(this.firstPage);
    }

    @Override
    public boolean canFinish() {
        if (this.firstPage.isPageComplete()) {
            return true;
        }
        return false;
    }

    @Override
    public boolean performFinish() {
        ProjectItem parentProjectItem = this.firstPage.getParentProjectItem();

        IFolder folder = CommonUtil.createFolder(parentProjectItem.getResource().getFullPath().append(this.firstPage.getFolderNm()));
        ProjectItem folderProjectItem = ProjectManager.getManager().newProjectItemFor(folder);
        folderProjectItem.setParent(parentProjectItem);
        parentProjectItem.addChild(folderProjectItem);

        ProjectManager.getManager().addProjectItem(folderProjectItem);

        return true;
    }

}
